package com.example.firstapp.broadcast

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.example.firstapp.R
import com.example.firstapp.databinding.ActivityBroadcast2Binding

class broadcast2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_broadcast2)
        val binding = com.example.firstapp.databinding.ActivityBroadcast2Binding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.sendmybroadcast.setOnClickListener {
            // 启动一个自定义广播
            println(123)
            val intent = Intent("com.example.firstapp.broadcast.MY_BROADCAST")
            intent.setPackage(packageName)
            sendBroadcast(intent,null)
        }
    }
}